using System.Collections;
using System.Collections.Generic;

internal class AndroidAudioPlayer : IAudioPlayer
{
	private Dictionary<string, int> m_StreamIds;

	private Dictionary<int, int> m_StreamOperationIds;

	public AndroidAudioPlayer(AudioManager audioManager)
	{
		m_StreamIds = new Dictionary<string, int>();
		m_StreamOperationIds = new Dictionary<int, int>();
		AndroidNativeAudio.makePool(5);
	}

	public IEnumerator Load(string audioFile)
	{
		if (!m_StreamIds.ContainsKey(audioFile))
		{
			int value = AndroidNativeAudio.load("Audio/" + audioFile + ".wav");
			m_StreamIds.Add(audioFile, value);
		}
		yield break;
	}

	public bool Unload(string audioFile)
	{
		if (!m_StreamIds.ContainsKey(audioFile))
		{
			return true;
		}
		int soundID = m_StreamIds[audioFile];
		m_StreamIds.Remove(audioFile);
		return AndroidNativeAudio.unload(soundID);
	}

	public void Resume(string audioFile)
	{
		if (m_StreamIds.ContainsKey(audioFile))
		{
			int key = m_StreamIds[audioFile];
			if (m_StreamOperationIds.ContainsKey(key))
			{
				int streamID = m_StreamOperationIds[key];
				AndroidNativeAudio.resume(streamID);
			}
		}
	}

	public void Pause(string audioFile)
	{
		if (m_StreamIds.ContainsKey(audioFile))
		{
			int key = m_StreamIds[audioFile];
			if (m_StreamOperationIds.ContainsKey(key))
			{
				int streamID = m_StreamOperationIds[key];
				m_StreamOperationIds.Remove(key);
				AndroidNativeAudio.pause(streamID);
			}
		}
	}

	public void PauseAll()
	{
		AndroidNativeAudio.pauseAll();
	}

	public void RemuseAll()
	{
		AndroidNativeAudio.resumeAll();
	}

	public void Play(string audioFile, float volume)
	{
		if (m_StreamIds.ContainsKey(audioFile))
		{
			int num = m_StreamIds[audioFile];
			int value = AndroidNativeAudio.play(num, volume);
			if (m_StreamOperationIds.ContainsKey(num))
			{
				m_StreamOperationIds[num] = value;
			}
			else
			{
				m_StreamOperationIds.Add(num, value);
			}
		}
	}

	public void PlayLoop(string audioFile)
	{
		if (!m_StreamIds.ContainsKey(audioFile))
		{
			return;
		}
		int num = m_StreamIds[audioFile];
		if (!m_StreamOperationIds.ContainsKey(num))
		{
			int value = AndroidNativeAudio.play(num, 1f, 1f, 1, -1);
			if (m_StreamOperationIds.ContainsKey(num))
			{
				m_StreamOperationIds[num] = value;
			}
			else
			{
				m_StreamOperationIds.Add(num, value);
			}
		}
	}

	public void Stop(string audioFile)
	{
		if (m_StreamIds.ContainsKey(audioFile))
		{
			int key = m_StreamIds[audioFile];
			if (m_StreamOperationIds.ContainsKey(key))
			{
				int streamID = m_StreamOperationIds[key];
				m_StreamOperationIds.Remove(key);
				AndroidNativeAudio.stop(streamID);
			}
		}
	}

	public void ReleasePool()
	{
		AndroidNativeAudio.releasePool();
	}
}
